package com.onlocation.objects;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import com.onlocation.util.StringUtil;

import java.util.List;

/**
 * Author: Steve Carrell
 * Date: 5/12/12
 */
public class LocalArrayAdapter extends ArrayAdapter<String> {
    private String currentLocation = "";
    private static final int layout = android.R.layout.simple_list_item_1;

    public LocalArrayAdapter(Context context, List<String> objects) {
        super(context, layout, objects);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView text = (TextView) super.getView(position, convertView, parent);

        if (StringUtil.equalsIgnoreNull(text.getText().toString(), currentLocation)) {
            text.setBackgroundColor(Color.DKGRAY);
        } else {
            text.setBackgroundColor(Color.BLACK);
        }

        return text;
    }

    public void updateCurrentLocation(String location) {
        currentLocation = location;
        notifyDataSetChanged();
    }
}
